<template>
  <div class="likes-wrapper">
    <div class="no-goods" v-if="!goodsLikes">
      <van-icon name="shop" />
      <p>您还没有收藏过商品</p>
    </div>

    <div class="likes-goods" v-else>
      <div class="goods-item" v-for="item in goodsLikes">
        <div class="goods-img">
          <img :src="item.thumb_url" alt="">
        </div>
        <div class="goods-text">
          <div class="goods-name">{{item.goods_name}}</div>
          <div class="goods-count">
            <span>{{item.customer_num}}人拼单</span>
            <i>-</i>
            <span>{{item.sales_tip}}</span>
          </div>
        </div>
        <div class="goods-bottom">
          <div class="bottom-line"></div>
          <div class="goods-price">
            <i>￥</i>
            <span>{{item.price/100}}</span>
          </div>
          <van-button type="danger" size="small">发起拼单</van-button>
          <div class="more">更多</div>
        </div>
      </div>

    </div>

    <choiceness-goods :hasMore="hasMore" :goodsList="goodsList"></choiceness-goods>
  </div>
</template>

<script>
import choicenessGoods from "../../../components/choicenessGoods/choiceness";
import axios from "axios";
import { recproductList, getgoodsLikes } from "../../../api/getDatas";
export default {
  components: {
    choicenessGoods
  },
  data() {
    return {
      goodsList: null,
      hasMore: false,
      count: 20,
      offset: 0,
      goodsLikes: null
    };
  },
  methods: {
    loadMore() {
      let offset = (this.offset += this.count);
      recproductList(this.count, offset).then(res => {
        this.goodsList = this.goodsList.concat(res.data.data);
        this.hasMore = res.data.has_more;
      });
    },
    initData() {
      recproductList(this.count, this.offset).then(res => {
        this.goodsList = res.data.data;
        // this.hasMore = res.data.has_more;
      });
      getgoodsLikes().then(res => {
        this.goodsLikes = res.data.data.goods_list;
      });
    }
  },
  created() {
    this.initData();
  }
};
</script>

<style lang="less" scoped>
.likes-goods {
  min-height: 4.25rem;
  .goods-item {
    position: relative;
    width: 100%;
    height: 1.35rem;
    background-color: #fff;
    .goods-img {
      margin-top: 0.05rem;
      margin-left: 0.1rem;
      position: absolute;
      width: 1.1rem;
      height: 1.1rem;
      overflow: hidden;
      background-color: #fafafa;
      background-size: contain;
      img {
        border: 0;
        max-width: 100%;
        width: auto;
        height: auto;
        vertical-align: top;
      }
    }
    .goods-text {
      padding-left: 1.4rem;
      padding-top: 0.13rem;
      .goods-name {
        max-height: 0.345rem;
        line-height: 0.18rem;
        color: #333;
        font-size: 0.14rem;
        vertical-align: bottom;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        word-break: break-all;
        overflow-y: hidden;
      }
      .goods-count {
        margin-top: 0.11rem;
        color: #9c9c9c;
        font-size: 0.13rem;
      }
    }
    .goods-bottom {
      padding-left: 1.4rem;
      padding-right: 0.12rem;
      position: absolute;
      bottom: 0;
      height: 0.42rem;
      width: 100%;
      .bottom-line {
        position: absolute;
        border-bottom: 1px solid #e5e5e5;
        width: 100%;
        bottom: 0;
        line-height: 0;
        height: 0;
        transform: scaleY(0.5);
      }
      .goods-price {
        max-width: 0.65rem;
        overflow: hidden;
        text-overflow: ellipsis;
        display: inline-block;
        color: #e02e24;
        font-size: 0.16rem;
        white-space: nowrap;
        position: absolute;
        top: 0.07rem;
      }
      .van-button {
        float: right;
        margin-left: 0.08rem;
      }
      .more {
        float: right;
        margin-top: -0.02rem;
        padding: 0.11rem 0;
        width: 0.4rem;
        height: 0.38rem;
        font-size: 0.14rem;
        color: #58595b;
        text-align: right;
      }
    }
  }
}
.no-goods {
  height: 4.25rem;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  p {
    color: #58595b;
    font-size: 0.16rem;
  }
  .van-icon-shop {
    color: #ccc;
    margin-bottom: 0.28rem;
    font-size: 0.7rem;
  }
}
</style>

